home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / doc / gpc / demos / conformantdemo.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-08  |  2.4 KB  |  80 lines

  1. {
  2. GPC demo program about conformant array parameters
  3. (Standard Pascal, level 1).
  4.  
  5. This is similar to BP's "open array parameters" (which GPC also
  6. supports), but easier to use, since it doesn't require `High' to
  7. get the higher limit of the array, and it doesn't automatically
  8. change the lower limit of the array to 0.
  9.  
  10. Copyright (C) 1999-2001 Free Software Foundation, Inc.
  11.  
  12. Author: Frank Heckenbach <frank@pascal.gnu.de>
  13.  
  14. This program is free software; you can redistribute it and/or
  15. modify it under the terms of the GNU General Public License as
  16. published by the Free Software Foundation, version 2.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program; see the file COPYING. If not, write to
  25. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  26. Boston, MA 02111-1307, USA.
  27.  
  28. As a special exception, if you incorporate even large parts of the
  29. code of this demo program into another program with substantially
  30. different functionality, this does not cause the other program to
  31. be covered by the GNU General Public License. This exception does
  32. not however invalidate any other reasons why it might be covered
  33. by the GNU General Public License.
  34. }
  35.  
  36. program ConformantArrayDemo;
  37.  
  38. procedure Test (const Foo : array [m .. n : Integer] of Char);
  39. var i : Integer;
  40. begin
  41.   Writeln ('The procedure was called with an `array [', m, ' .. ', n, '] of Char'' with the value:');
  42.   Write ('(');
  43.   for i := m to n do
  44.     begin
  45.       Write ('''', Foo [i], '''');
  46.       if i < n then Write (', ')
  47.     end;
  48.   Writeln (')');
  49.   Writeln
  50. end;
  51.  
  52. const
  53.   Foo : array [3 .. 5] of Char = ('F', 'o', 'o');
  54.   Bar : array [-1 .. 1] of Char = 'Bar'; { Initializing an array of char like
  55.                                            a string (BP compatible) }
  56.  
  57. var
  58.   a, b : Integer;
  59.  
  60. begin
  61.   Test (Foo);
  62.   Test (Bar);
  63.   Test ('Baz'); { One can also pass a string constant }
  64.   Test (Foo [3 .. 4]); { array slice access }
  65.  
  66.   repeat
  67.     Write ('Enter a lower and higher bound for an array: ');
  68.     Readln (a, b)
  69.   until a <= b;
  70.  
  71.   { A dynamic array (Extended Pascal) declared in the
  72.     statement part (GPC extension) }
  73.   var t : array [a .. b] of Char;
  74.  
  75.   Write ('Enter the content of the array: ');
  76.   Readln (t);
  77.   Writeln;
  78.   Test (t)
  79. end.
  80.